package com.masterclient.app.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import com.masterclient.app.R;
import com.masterclient.app.utils.CommonUtil;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @auther hxm
 * @date 2019/9/8.
 */
public class FansImageDialog extends Dialog {


    @BindView(R.id.dialog_vip_img)
    ImageView dialogVipImg;
    @BindView(R.id.dialog_vip_close)
    ImageView dialogVipClose;

    private String imgUrl,url;
    private Context context;

    private OnChooseListerner onChooseListerner;

    public interface OnChooseListerner{
        void cancel();
        void confirm();
    }

    public FansImageDialog(@NonNull Context context, String imgUrl, String url) {
        super(context, R.style.MyDialog);
        this.imgUrl = imgUrl;
        this.url = url;
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_fans);
        ButterKnife.bind(this);

        ViewTransformUtil.glideImageView(context,imgUrl,dialogVipImg,R.color.transparent);
        dialogVipClose.setVisibility(View.VISIBLE);
        dialogVipImg.setVisibility(View.VISIBLE);

    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowparams = window.getAttributes();
        windowparams.width = ScreenUtils.getScreenWidth();
        window.setGravity(Gravity.BOTTOM);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }

    @OnClick({R.id.tv_to_see, R.id.dialog_vip_close})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_to_see:
                dismiss();
                if (onChooseListerner!=null){
                    onChooseListerner.confirm();
                }
                CommonUtil.goAnyWhere(context, url,"","","","");
                break;
            case R.id.dialog_vip_close:
                dismiss();
                if (onChooseListerner!=null){
                    onChooseListerner.cancel();
                }
                break;
        }
    }
}
